<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <link rel="apple-touch-icon" sizes="76x76" href="{_INDEX_STATIC_}/moban/assets/img/apple-icon.png">
    <link rel="icon" type="image/png" href="{_INDEX_STATIC_}/moban/assets/img/favicon.png">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title>首页 | {$system_name}</title>
    <meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no'
        name='viewport' />
    <link href="{_INDEX_STATIC_}/moban/assets/css/bootstrap.min.css" rel="stylesheet" />
    <link href="{_INDEX_STATIC_}/moban/assets/css/now-ui-kit.css?v=1.1.0" rel="stylesheet" />
    <link href="{_INDEX_STATIC_}/moban/assets/css/font-awesome.min.css" rel="stylesheet" />
</head>

<body class="index-page sidebar-collapse">

    <!-- 引入导航栏 -->
    {include file='public/header'}

    <div class="container" style="min-height: 480px;">

        <!-- 所有需要下载的数据 -->
        <div class="row" style="height: 400px; overflow: hidden;overflow-y: scroll;margin-top: 10px;">
            <div class="col-md-12">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th style='vertical-align: middle;text-align: center;'>#</th>
                            <!-- <th style='vertical-align: middle;text-align: center;'>#</th> -->
                            {volist name="classify_table_info.table_content.names" id="row"}
                            <th style='vertical-align: middle;text-align: center;'>{$row}</th>
                            {/volist}
                            <th style="width:260px;vertical-align: middle;text-align: center;">状态</th>
                        </tr>
                    </thead>
                    <tbody>
                        {volist name="achievement_classify_table_other_info" id="row" key="k"}
                        <!-- 初始化一个变量 -->
                        <!-- {$k=0} -->
                        <tr>
                            <td style='vertical-align: middle;text-align: center;'>
                                <input type="checkbox" onclick="cbox_checked(this)" value="{$row.id}">
                            </td>
                            <!-- <td style='vertical-align: middle;text-align: center;'>{$row.id}</td> -->
                            {volist name="classify_table_info.table_content.names" id="var"}
                            {if
                            condition="$classify_type_list[$classify_table_info.table_content.selects[$k]-1]['name'] ==
                            '时间'"}
                            <td style='vertical-align: middle;text-align: center;'>
                                {$row[$classify_table_info.table_content.cols[$k]] | date='Y-m-d'} </td>
                            {else /}
                            {if
                            condition="$classify_type_list[$classify_table_info.table_content.selects[$k]-1]['name'] ==
                            '数值'"}
                            <td style='vertical-align: middle;text-align: center;'>
                                {$row[$classify_table_info.table_content.cols[$k]] / 100 | floatval} </td>
                            {else /}
                            <td style='vertical-align: middle;text-align: center;'>
                                {$row[$classify_table_info.table_content.cols[$k]]} </td>
                            {/if}
                            {/if}
                            <!-- $k 自增 -->
                            <!-- {$k++} -->
                            {/volist}
                            <td style='vertical-align: middle;text-align: center;'>
                                <div class="btn btn-round">
                                    {$row.status | achievement_submit_status}
                                </div>
                            </td>
                        </tr>
                        {/volist}
                    </tbody>
                </table>
            </div>
        </div>

        <!-- 分割线 -->
        <!-- <div class="row" style="border: 1px solid #ddd; height: 2px;margin-top: 15px;margin-bottom: 5px;">
        </div> -->

        <!-- 选中ID -->
        <!-- <div class="row" style="height: 90px; overflow: hidden;overflow-y: scroll;">
            <div class="col-md-12" id="cbox_ids">

            </div>
        </div> -->

        <!-- 按钮 -->
        <div class="row">
            <div class="col-md-6" style="text-align: right;">
                <button id="download" class="btn btn-success btn-round btn-lg">点击下载</button>
            </div>
            <div class="col-md-6">
                <button id="back" class="btn btn-info btn-round btn-lg">点击返回</button>
            </div>
        </div>
    </div>
    <!-- 引入页脚 -->
    {include file='public/footer'}

    <script>
        // 复选框 ids
        var ids = [];
        // 复选框点击
        function cbox_checked(obj) {
            var cbox = $(obj);
            if (obj.checked) {
                ids.push(cbox.val());
            } else {
                var tmp_data = [];
                var n = ids.length;
                for (let index = 0; index < n; index++) {
                    var tmp_ids = ids[index];
                    if (cbox.val() != tmp_ids) {
                        tmp_data.push(tmp_ids);
                    }
                }
                ids = tmp_data;
            }
            $('#cbox_ids').html(ids.toString());
        }

        // 点击下载
        $('#download').on('click', function () {
            var url = "{:url('Achievement/import_excel')}";
            var data = {
                'cid': "{$cid}",
                'status': 1,
                'ids': ids.toString() == '' ? '' : ids.toString()
            };
            $.ajax({
                url: url,
                data: data,
                type: "POST",
                dataType: 'JSON',
                success: function (res) {
                    if (res.code == 0) {
                        redirect_url(res.url);
                        return layer.msg(res.msg, { icon: 1, time: 900 });
                    } else {
                        return layer.msg(res.msg, { icon: 2, time: 900 });
                    }

                },
            });
        });

        // 点击返回
        $('#back').on('click', function () {
            redirect_url("{:url('Achievement/details')}?cid={$cid}");
        });

        // 重定向
        function redirect_url(url) {
            window.location.href = url;
        }
    </script>

</body>

</html>